
import 'dart:io';

import 'package:eq/src/core.dart';
import 'package:eq/src/interpreter.dart';
import 'package:eq/src/utils.dart';
///
///主机信息模块
///
///获取当前运行主机的信息
///

void addHostFunctions(Module module) {
  addNativeFunction("getcurrentHost", _getcurrentHost, module);
  addNativeFunction("getEnvironment", _getEnvironment, module);
}

Value _getcurrentHost(List<Value> args) {
  var t = {
    "localHostname": Platform.localHostname,
    "operatingSystem": Platform.operatingSystem,
    "localeName": Platform.localeName,
    "numberOfProcessors": Platform.numberOfProcessors.toString(),
    "operatingSystemVersion": Platform.operatingSystemVersion,
    "pathSeparator": Platform.pathSeparator
  };
  if (args.isEmpty) {
    return Value(ValueType.STRING_VALUE, t);
  } else if (args.length == 1) {
    return Value(ValueType.STRING_VALUE, t[args[0].value]);
  } else {
    Map t1 = {};
    for (var element in args) {
      t1.putIfAbsent(element.value, () => t[element.value]);
    }
    return Value(ValueType.STRING_VALUE, t1.toString());
  }
}

Value _getEnvironment(List<Value> list) =>
    Value(ValueType.STRING_VALUE, Platform.environment.toString());
